package com.ruoyi.base.mqtt;

import com.ruoyi.common.annotation.Anonymous;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Anonymous
@RestController
public class PublishController {

    @Resource
    private MqttServer mqttserver;

    @RequestMapping(value = "testPublish")
    public String testPublish(String topic, String msg, int qos) {

        mqttserver.sendMQTTMessage(topic, msg, qos);
        return "发送了一条消息：主题‘"+topic+"’，内容:"+msg+"，级别 "+qos;
        //http://localhost:8080/testPublish?topic=test&qos=0&msg=8081
    }

    @RequestMapping(value = "testSubscribe")
    public String testSubscribe(String topic, int qos) {
        mqttserver.init(topic, qos);
        return "订阅主题'"+topic+"'成功";
        //http://localhost:8080/testSubscribe?topic=test&qos=0
    }

    @RequestMapping(value = "testUnSubscribe")
    public String testUnSubscribe(String topic) {
        mqttserver.unionInit(topic);
        return "取消订阅主题："+topic;
        //http://localhost:8080/testUnSubscribe?topic=test
    }

}
